import { Component, OnInit,Input, ChangeDetectionStrategy } from '@angular/core';

@Component({
  selector: 'test-lifecycle',
  templateUrl: './lifecycle.component.html',
  styleUrls: ['./lifecycle.component.scss'],
  changeDetection:ChangeDetectionStrategy.OnPush
})
export class LifecycleComponent implements OnInit {

  @Input()
  public title:string = "默认标题";

  public logs:Array<any>=[];
  constructor() {
    /**
     * 构造函数里面最好只做一些简单的赋值操作，不要做复杂的逻辑
     * 获取服务端数据、业务逻辑等不要实现在构造函数里面
     * 想知道详细的原因请看这篇解释http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/
     */
    this.logs.push("constructor....")
   }

  ngOnInit() {
    this.logs.push("ngOnInit....")
  }

  ngOnChanges(){
    this.logs.push("ngOnChanges....")
  }

  ngDoCheck(){
    console.log("sdfhsdjkfhsaf");
    
    this.logs.push("ngDoCheck....")
  }

  ngAfterContentInit(){
    this.logs.push("ngAfterContentInit....")
  }

  ngAfterContentChecked(){
    this.logs.push("ngAfterContentChecked....")
  }

  ngAfterViewInit(){
    this.logs.push("ngAfterViewInit....")
  }

  ngAfterViewChecked(){
    this.logs.push("ngAfterViewChecked....")
  }

  ngOnDestory(){
    this.logs.push("ngOnDestory....")
  }

}
